package com.lfg.leetcode.leetcode0;

import java.util.Stack;

public class No20IsValid {
    public static boolean isValid(String s) {
        if (null == s || "".equals(s)) {
            return true;
        }
        if (s.length() < 2) {
            return false;
        }
        int i = 0;
        int length = s.length();
        Stack<Character> stack = new Stack<Character>();
        while (i < length) {
            Character c = s.charAt(i);
            i++;
            if (c == '(')
                stack.push(')');
            else if (c == '{')
                stack.push('}');
            else if (c == '[') {
                stack.push(']');
            } else if (stack.isEmpty() || stack.pop() != c) {
                return false;
            }
        }
        return stack.isEmpty();
    }


    public static void main(String[] args) {
        System.out.println(isValid("[])"));
//        System.out.println(threeSum(new int[]{-2,0,0,2,2}));
    }
}
